<? 
	
?>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.jqprint.0.3.js"></script>
<?
$currentFile = $_SERVER["SCRIPT_NAME"];
$parts = Explode('/', $currentFile);
$currentFile = $parts[count($parts) - 1];


if($currentFile == "booking.php" || $currentFile == "checkin2.php" || $currentFile == "editBooking.php"){?>
<script
	type="text/javascript" src="js/datepicker/datepicker.js"></script>
<script
	type="text/javascript" src="js/datepicker/eye.js"></script>
<script
	type="text/javascript" src="js/datepicker/utils.js"></script>
<script
	type="text/javascript" src="js/datepicker/layout.js?ver=1.0.2"></script>
	

<script type='text/javascript' src='autocomplete/lib/jquery.bgiframe.min.js'></script>
<script type='text/javascript' src='autocomplete/lib/jquery.ajaxQueue.js'></script>
<script type='text/javascript' src='autocomplete/lib/thickbox-compressed.js'></script>
<script type='text/javascript' src='autocomplete/jquery.autocomplete.js'></script>

<link rel="stylesheet" type="text/css" href="autocomplete/jquery.autocomplete.css" />
<link rel="stylesheet" type="text/css" href="autocomplete/lib/thickbox.css" />
	
<?
if($currentFile == "editBooking.php"){
	$reserv_id = $_REQUEST['reserv_id'];
	echo '<script type="text/javascript" src="js/datepicker/datePickerData.php?reserv_id=' . $reserv_id . '"></script>';
}
else
echo '<script type="text/javascript" src="js/datepicker/datePickerData.php"></script>';
?>
<script
	type="text/javascript" src="js/jquery.validationEngine.js"></script>
<link
	rel="stylesheet" href="css/datepicker.css" type="text/css"
	charset="utf-8" />
<link
	rel="stylesheet" href="css/validationEngine.jquery.css" type="text/css"
	charset="utf-8" />
<script type="text/javascript" charset="utf-8">
	var mode = "1";
	var flagEdit = "0";
	$(document).ready(function() {
		$("#booking-form").validationEngine({
			success :  false,
			failure : function() {}
		})
	});
	$(function(){
     $("select#roomType").change(function(){
         var inputDate = $("#fromDate").val()+","+$("#toDate").val();
       $.getJSON("./validate/validateRoomType.php",{id: $(this).val(),date: inputDate, ajax: 'true'}, function(j){
         var options = '';
         for (var i = 0; i < j.length; i++) {
           options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
         }
         $("select#roomID").html(options);
       })
     })
   });
	</script>
<?
}

if($currentFile == "booking.php"){?>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
	$("#result_cutomer").autocomplete("search.php", {
		width: 190,
		selectFirst: true,
		minChars: 0,
		matchContains: false,
		scrollHeight: 220,
		formatItem: function(data, i, total) {
			return data[0];
		}
	}).result(function(event, data, formatted) {
		if (data){
			$("#search_cutomer").val(data[1]);
			searchCustomer();
		}
	});
	
	//$("#booking-form").hide();
/*  $(".bookfrom2").hide();
   $("#radio01").click(function(){
	$('#roomID').empty();
               mode = "1";
			$("#booking-form").show("slow");	
   			   $(".bookfrom1").show("slow");
   			   $(".bookfrom2").hide("slow"); 
			   $("#roomlist").empty();

   });
   $("#radio02").click(function(){*/
	$("#radio01").hide();
	$("#radio02").hide();
	$('#roomID').empty();
	  mode = "2";
	$("#booking-form").show();	
	$(".bookfrom1").hide();
	$(".bookfrom2").show();
	$(".night").hide(); 
	$("#roomlist").html("<div style='float: left; margin-right: 10px; margin-left: 50px;'>no item found</div>");
   /*});*/

});





</script>
<?
}

if($currentFile == "editBooking.php"){?>
<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
		$("#result_cutomer").autocomplete("search.php", {
			width: 190,
			selectFirst: true,
			minChars: 0,
			matchContains: false,
			scrollHeight: 220,
			formatItem: function(data, i, total) {
				return data[0];
			}
		}).result(function(event, data, formatted) {
			if (data){
				$("#search_cutomer").val(data[1]);
				searchCustomer();
			}
		});
		
		mode = "2";
		flagEdit = "1";
		$(".editTime").hide();
		$(".bookfrom1").hide();
		$(".bookfrom2").show();	
		$("#chkInputEditDate").click(function(){
			if ( $( "#chkInputEditDate:checked" ).val() == 1 ) {
				$(".editTime").show();	
				$("#fromDate").show();	
	   			$("#toDate").show();
			}else{
				$(".editTime").hide();	
				$("#fromDate").hide();	
	   			$("#toDate").hide();
			}
		});
	});
	</script>
<?
}

if($currentFile == "editBooking.php" || $currentFile == "booking.php"){?>
	<script type="text/javascript" charset="utf-8">
		function searchCustomer(){
			if($("#search_cutomer").val() != ""){
			
				$.ajax({
					url: "search.php",
					secureuri:false,			
					dataType: 'json',
					data:{value:$("#search_cutomer").val(), mode:'search'},
					success: function(data, status){
						if(typeof(data.error) != 'undefined')
						{
							if(data.error != '')
							{
								alert(data.error);
							}else
							{
								if(data.total == 1){
									$("#customer_name").val(data.customer_name);
									$("#customer_surname").val(data.customer_surname);
									$("#customer_id").val(data.customer_id);
									$("#customer_email").val(data.customer_email);
									$("#customer_tel").val(data.customer_tel);
									$("#customer_fax").val(data.customer_fax);
									<? if($currentFile == "editBooking.php"){ ?>
										$("#customer_address").val(data.customer_address);
									<? } ?>
										if(data.customer_group_name != "" && data.customer_group_name != 0){
											$("#group").attr('checked','true');
											$(".group").show();
											$("#customer_group_name").val(data.customer_group_name);
										}else{
											$("#name").attr('checked','true');
											$(".group").hide();
											$("#customer_group_name").val('');
										}
								}else{
									//can not found
								}	
							}
						}
					}
				});
			}
		}
		function chkCustomerType(){
			if($("#group").attr('checked')){
				$(".group").show();
				//$("#customer_group_name").addClass("validate[required] text-input");
			}else{
				$(".group").hide();
				//$("#customer_group_name").removeClass("validate[required] text-input");
			}
		}
	</script>
<?
}

if($currentFile == "addUser.php" || $currentFile == "editUser.php"){?>
<script
	type="text/javascript" src="js/jquery.validationEngine.js"></script>
<link
	rel="stylesheet" href="css/validationEngine.jquery.css" type="text/css"
	charset="utf-8" />
<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
		$("#booking-form").validationEngine({
			success :  false,
			failure : function() {}
		})
	});
	</script>
<?
}
if($currentFile == "checkin.php"){?>
<script
	type="text/javascript" src="js/jquery.validationEngine.js"></script>
<link
	rel="stylesheet" href="css/validationEngine.jquery.css" type="text/css"
	charset="utf-8" />
<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
		$("#checkin-form").validationEngine({
			success :  false,
			failure : function() {}
		})
	});
	$(function(){
     $("input#find_reserv").click(function(){
       $.getJSON("./validate/validateCheckIn.php",{reserv_gid: $("input#reserv_gid").val(),customer_name: $("input#customer_name").val(),customer_surname: $("input#customer_surname").val(), ajax: 'true'}, function(j){
          var string = '';
          var check = false;
          var check_group = "";
          if(j==""){
              check = false;
             string += '<center style="margin-left:-115px;"><img src="./img/error.png"><br>ค้นหาไม่พบ ! กรุณาลองอีกครั้ง</center>';
          }
         else{
             //$("p.submit").show();
             check = true;
             for(var m = 0;m<j.length;m++){
              /*string += '<form action="doCheckIn.php" method="POST" id="checkin-form">';
              string += '<table>';
              string += '<tr><td><label for="reserv_id">รหัสการจอง : </label></td><td>' + j[i].reserv_gid + '<input type="hidden" id="reserv_id" name="reserv_id" value="' + j[i].reserv_gid + '" size="30" /></td></tr>';
              string += '<tr><td><label for="reserv_begin">วันที่เข้าพัก : </label></td><td>' + j[i].reserv_begin + '</td></tr>';
              string += '<tr><td><label for="reserv_end">วันที่ออก : </label></td><td>' + j[i].reserv_end + '</td></tr>';
              string += '<tr><td><label for="room_id">หมายเลขห้อง : </label></td><td>' + j[i].room_list + '<input type="hidden" id="room_id" name="room_id" value="' + j[i].room_list + '" size="30" /></td></tr>';
              string += '<tr><td><label for="customer_id">รหัสประชาชน : </label></td><td><input type="text" id="customer_id" name="customer_id" value="' + j[i].customer_id + '" size="30" /></td></tr>';
	 		  string += '<tr><td><label for="customer_address">ที่อยู่ : </label></td><td><textarea id="customer_address" name="customer_address" value="' + j[i].customer_address + '"cols="50" rows="3" /></td></tr>';
              string += '<tr><td><label for="cid">รหัสลูกค้า : </label></td><td>' + j[i].cid + '<input type="hidden" id="cid" name="cid" value="' + j[i].cid + '" size="30" /></td></tr>';
              string += '<tr><td><label for="customer_name">ชื่อ : </label></td><td>' + j[i].customer_name + '</td></tr>';
              string += '<tr><td><label for="customer_surname">นามสกุล : </label></td><td>' + j[i].customer_surname + '</td></tr>';
              string += '<tr><td><label for="customer_email">อีเมล์ : </label></td><td>' + j[i].customer_email + '</td></tr>';
              string += '<tr><td><label for="customer_tel">โทรศัพท์ : </label></td><td>' + j[i].customer_tel + '</td></tr>';
              string += '<tr><td><label for="customer_fax">แฟกซ์ : </label></td><td>' + j[i].customer_fax + '</td></tr>';
              string += '<tr><td></td><td><p class="submit" style="display:none;"><input type="submit" value="ยืนยันการเข้าพัก" /></p></td></tr>'
              string += '</table>';
              string += '<hr>';
              string += '</form>';*/
              var color = 0;
	              for(var n = 0;n<j[m].length;n++){
	            	 /* Header checkin information*/
	            	 if(n == 0){
	            		 string += '<form action="doCheckIn.php" method="POST" id="'+j[m][n].reserv_gid+'">';
		                 string += '<table>';
		                 string += '<tr><td><label for="reserv_id">รหัสการจอง : </label></td><td>' + j[m][n].reserv_gid + '<input type="hidden" id="reserv_gid" name="reserv_gid" value="' + j[m][n].reserv_gid + '" size="30" /></td></tr>';
		                 string += '<tr><td><label for="reserv_begin">วันที่เข้าพัก : </label></td><td>' + j[m][n].reserv_begin + '</td></tr>';
		                 string += '<tr><td><label for="reserv_end">วันที่ออก : </label></td><td>' + j[m][n].reserv_end + '</td></tr>';
		                 //string += '<tr><td><label for="room_id">หมายเลขห้อง : </label></td><td>' + j[m][n].room_id + '<input type="hidden" id="room_id" name="room_id" value="' + j[m][n].room_list + '" size="30" /></td></tr>';
		                 string += '<input type="hidden" id="'+j[m][n].reserv_gid+'" name="reserv_id" value="" />';
		                 string += '<tr><td><label for="customer_id">รหัสประชาชน : </label></td><td><input type="text" id="customer_id" name="customer_id" value="' + j[m][n].customer_id + '" size="30" /></td></tr>';
		   	 		  	 string += '<tr><td><label for="customer_address">ที่อยู่ : </label></td><td><textarea id="customer_address" name="customer_address" value="' + j[m][n].customer_address + '"cols="50" rows="3" /></td></tr>';
		                 string += '<tr><td><label for="cid">รหัสลูกค้า : </label></td><td>' + j[m][n].cid + '<input type="hidden" id="cid" name="cid" value="' + j[m][n].cid + '" size="30" /></td></tr>';
		                 string += '<tr><td><label for="customer_name">ชื่อ : </label></td><td>' + j[m][n].customer_name + '</td></tr>';
		                 string += '<tr><td><label for="customer_surname">นามสกุล : </label></td><td>' + j[m][n].customer_surname + '</td></tr>';
		                 string += '<tr><td><label for="customer_email">อีเมล์ : </label></td><td>' + j[m][n].customer_email + '</td></tr>';
		                 string += '<tr><td><label for="customer_tel">โทรศัพท์ : </label></td><td>' + j[m][n].customer_tel + '</td></tr>';
		                 string += '<tr><td><label for="customer_fax">แฟกซ์ : </label></td><td>' + j[m][n].customer_fax + '</td></tr>';
		                 //string += '<tr><td></td><td><p class="submit" style="display:none;"><input type="button" value="ยืนยันการเข้าพัก" onclick="getCheckedValue('+j[m][n].reserv_gid+');" /></p></td></tr>';
		                 string += '</table>';
		                 string += '<table id="table">';
	            	 }

			        /* roomlist checkin information*/
		                 if(color%2 == 0){
		         			string += '<tr class="odd">';
		         		}else{
		         			string += '<tr>';
		         		}
			         		string += '<td><input type="checkbox" id="'+j[m][n].reserv_gid+'" value="'+j[m][n].reserv_id+'"></input></td>';
			         		string += '<td>'+j[m][n].room_id+'</td>';
			         		string += '<td>'+j[m][n].roomtype_name+'</td>';
			         		string += '<td>'+j[m][n].roomsize_name+'</td>';
			         		string += '<td>'+j[m][n].room_cost+'</td>';
			         		string += '</tr>';
			       /* footer checkin information*/	
			         if(n == j[m].length-1){
			        	 string += '<tr style="border:0;"><td style="border:0;" colspan="6"><p class="submit" style="display:none;"><input type="button" value="ยืนยันการเข้าพัก" onclick="getCheckedValue('+j[m][n].reserv_gid+');" /></p></td></tr>';
			         }
			         	color++;
	              }
	              	 string += '</table>';
	                 string += '<hr>';
	                 string += '</form>'; 
             }
         }    
         $("#reservdata").html(string);
         if(check){
        	 $("p.submit").show();
         }else{
        	 $("p.submit").hide();
         }
       })
     })
   });
	   function getCheckedValue(id){
		   var ids   = new Array();
		    jQuery("input[id='"+id+"']:checkbox:checked").each(function(){
		         ids.push(this.value);
		    });
            $("input[id='"+id+"']:hidden").val(ids);
            $('#'+id).submit();
		   /*$.post("doCheckIn.php", { 'name[]': ids} ,function(data) {
			   alert("Data Loaded: " + data);
		   });*/
	   }
	</script>
<?
}
if($currentFile == "confirmBooking.php"){?>
<script
	type="text/javascript" src="js/jquery.validationEngine.js"></script>
<link
	rel="stylesheet" href="css/validationEngine.jquery.css" type="text/css"
	charset="utf-8" />
<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
		$("#checkin-form").validationEngine({
			success :  false,
			failure : function() {}
		})
	});
	$(function(){
     $("input#find_reserv").click(function(){
       $.getJSON("./validate/validateConfirm.php",{reserv_gid: $("input#reserv_gid").val(),customer_name: $("input#customer_name").val(),customer_surname: $("input#customer_surname").val(), ajax: 'true'}, function(j){
          var string = '';
          var check = false;
          if(j==""){
             check = false;
             string += '<center style="margin-left:-115px;"><img src="./img/error.png"><br>ค้นหาไม่พบ ! กรุณาลองอีกครั้ง</center>';
             //$("p.submit").hide();
          }
         else{
        	 check = true;
             for(var i = 0;i<j.length;i++){
              string += '<form action="doConfirmBooking.php" method="POST" id="checkin-form">';
              string += '<table>';
              string += '<tr><td><label for="reserv_id">รหัสการจอง : </label></td><td>' + j[i].reserv_gid + '<input type="hidden" id="reserv_gid" name="reserv_gid" value="' + j[i].reserv_gid + '" size="30" /></td></tr>';
              string += '<tr><td><label for="reserv_begin">วันที่เข้าพัก : </label></td><td>' + j[i].reserv_begin + '</td></tr>';
              string += '<tr><td><label for="reserv_end">วันที่ออก : </label></td><td>' + j[i].reserv_end + '</td></tr>';
              string += '<tr><td><label for="room_id">หมายเลขห้อง : </label></td><td>' + j[i].room_list + '<input type="hidden" id="room_list" name="room_list" value="' + j[i].room_list + '" size="30" /></td></tr>';
              string += '<tr><td><label for="cid">รหัสลูกค้า : </label></td><td>' + j[i].cid + '<input type="hidden" id="cid" name="cid" value="' + j[i].cid + '" size="30" /></td></tr>';
              string += '<tr><td><label for="customer_name">ชื่อ : </label></td><td>' + j[i].customer_name + '</td></tr>';
              string += '<tr><td><label for="customer_surname">นามสกุล : </label></td><td>' + j[i].customer_surname + '</td></tr>';
              string += '<tr><td><label for="customer_email">อีเมล์ : </label></td><td>' + j[i].customer_email + '</td></tr>';
              string += '<tr><td><label for="customer_tel">โทรศัพท์ : </label></td><td>' + j[i].customer_tel + '</td></tr>';
              string += '<tr><td><label for="customer_fax">แฟกซ์ : </label></td><td>' + j[i].customer_fax + '</td></tr>';
              string += '<tr><td><label for="reserv_gcost">จำนวนเงิน : </label></td><td>' + moneyConvert(j[i].reserv_gcost) + '<input type="hidden" id="reserv_cost" name="reserv_cost" value="' + j[i].reserv_gcost + '"></td></tr>';
              string += '<tr><td><label for="reserv_gcost">เงินมัดจำ : </label></td><td><input type="text" id="reserv_pledge" name="reserv_pledge" value="' + j[i].reserv_cashpledge + '"></td></tr>';
              string += '<tr><td></td><td><p class="submit" style="display:none;"><input type="submit" value="ยืนยันการจอง" /></p></td></tr>';
              string += '</table>';
              string += '<hr>';
              string += '</form>';
             }
              
              /*string += '<p><label for="reserv_id">รหัสการจอง : </label>' + j[0].reserv_id + '<input type="hidden" id="reserv_id" name="reserv_id" value="' + j[0].reserv_id + '" size="30" /></p>';
              string += '<p><label for="reserv_begin">วันที่เข้าพัก : </label>' + j[0].reserv_begin + '</p>';
              string += '<p><label for="reserv_end">วันที่ออก : </label>' + j[0].reserv_end + '</p>';
              string += '<p><label for="room_id">หมายเลขห้อง : </label>' + j[0].room_id + '<input type="hidden" id="room_id" name="room_id" value="' + j[0].room_id + '" size="30" /></p>';
              string += '<p><label for="cid">รหัสลูกค้า : </label>' + j[0].cid + '<input type="hidden" id="cid" name="cid" value="' + j[0].cid + '" size="30" /></p>';
              string += '<p><label for="customer_name">ชื่อ : </label>' + j[0].customer_name + '</p>';
              string += '<p><label for="customer_surname">นามสกุล : </label>' + j[0].customer_surname + '</p>';
              string += '<p><label for="customer_email">อีเมล์ : </label>' + j[0].customer_email + '</p>';
              string += '<p><label for="customer_tel">โทรศัพท์ : </label>' + j[0].customer_tel + '</p>';
              string += '<p><label for="customer_fax">แฟกซ์ : </label>' + j[0].customer_fax + '</p>';*/

              //$("p.submit").show();
         }    
         $("#reservdata").html(string);
         if(check){
        	 $("p.submit").show();
         }else{
        	 $("p.submit").hide();
         }
       })
     })
   });
	</script>
<?
}
?>

<link href="facebox/src/facebox.css" media="screen" rel="stylesheet" type="text/css" />
<!-- /* <script src="facebox/lib/jquery.js" type="text/javascript"></script> */ -->
<script src="facebox/src/facebox.js" type="text/javascript"></script>
  <script type="text/javascript">
    /*jQuery(document).ready(function($) {
      $('a[rel*=facebox]').facebox({
        loading_image : '/facebox/src/loading.gif',
        close_image   : '/facebox/src/closelabel.gif'
      }) 
    })*/

    jQuery(document).ready(function($) {
      $('a[rel*=facebox]').facebox({
        /*
loading_image : 'facebox/src/loading.gif',
        close_image   : 'facebox/src/closelabe.png'
*/
      }); 
    });
    $.facebox.settings.closeImage = 'facebox/src/closelabel.png';
	$.facebox.settings.loadingImage = 'facebox/src/loading.gif';
</script>

<script type="text/javascript">
	function printPage(element){
		$("#"+element).jqprint();
	}
	
	function moneyConvert(value){
			var buf = "";
			var sBuf = "";
			var j = 0;
			value = String(value);
 
			if (value.indexOf(".") > 0) {
				buf = value.substring(0, value.indexOf("."));
			} else {
				buf = value;
			}
			if (buf.length%3!=0&&(buf.length/3-1) > 0) {
				sBuf = buf.substring(0, buf.length%3) + ",";
				buf = buf.substring(buf.length%3);
			}
			j = buf.length;
			for (var i = 0; i <(j/3-1); i++) {
				sBuf = sBuf+buf.substring(0, 3) + ",";
				buf = buf.substring(3);
			}
			sBuf = sBuf+buf;
			if (value.indexOf(".") > 0) {
				value = sBuf + value.substring(value.indexOf("."));}
			else {
				value = sBuf;
			}
			return value;
		}
	//$('#divOpera').jqprint({ operaSupport: true });
</script>

<?
/*
if($currentFile == "checkout.php"){
	echo '<script type="text/javascript" >$("#table").hide();</script>';
}
*/
?>

